import Mock from 'mockjs'



const data = Mock.mock({
  "car|10": [{
    "id": "@id",
    "url": "@image(100x100, @color)",
    "price|10-1000": 1,
    "title": "@ctitle",
    "desc": "@cword(10, 20)"
  }]
})



// 列表拦截请求  
Mock.mock('/api/car', () => {
  return {
    code: 200,
    data: data.car
  }
})

// 详情接口
Mock.mock('/api/detail', 'post', (req) => {
  // 解构出来请求的id
  const { id } = JSON.parse(req.body)
  // 筛选数据
  const item = data.car.find(item => item.id === id)

  return {
    code: 200,
    data: item
  }
})